﻿using Dapper;
using MiniApiProject.Models;

namespace MiniApiProject.Data;

public class DbInitializer(IDbConnectionFactory dbConnectionFactory, ILogger<DbInitializer> logger)
{
	public async Task Init()
	{
		var connection = await dbConnectionFactory.GetConnection();
		await connection.ExecuteAsync("""
			CREATE TABLE IF NOT EXISTS Books (
				Id INTEGER PRIMARY KEY AUTOINCREMENT,
				Title TEXT NOT NULL,
				Author TEXT,
				Isbn TEXT,
				Price REAL,
				PageCount INTEGER,
				PublishDate TEXT
			);
			""");
	}
}
